package 序列化和反序列化克隆;

/**
 * 序列化和反序列化实现深克隆
 *
 * @author oy
 * @version 1.0
 * @date 2018年8月9日
 * @time 下午8:58:53
 */
public class Test {
    public static void main(String[] args) {
        Car car = new Car("BYD", "black");
        car1 car1 = new car1("干饭", 111);
        Person p1 = new Person("张三", 20,car ,car1);


        Person p2 = cloneUtil.cloneObject(p1);
        Person p3 = cloneUtil.cloneObject(p2);

        System.out.println("P1:" + p1);//P1:Person [name=张三, age=20, car=Car [name=BYD, color=black]]
        System.out.println("p2:" + p2);//p2:Person [name=张三, age=20, car=Car [name=BYD, color=black]]
        System.out.println("p3:" + p3);//p2:Person [name=张三, age=20, car=Car [name=BYD, color=black]]
        System.out.println("================================================================================");
        if (p2 != null) {
            car.setName("宝马");
            car.setColor("red");
        }

        System.out.println("P1:" + p1);//P1:Person [name=张三, age=20, car=Car [name=宝马, color=red]]
        System.out.println("p2:" + p2);//p2:Person [name=张三, age=20, car=Car [name=BYD, color=black]]
        System.out.println("p3:" + p3);//p2:Person [name=张三, age=20, car=Car [name=BYD, color=black]]
        System.out.println("================================================================================");
        if (p3 != null) {
            car1.setName("宝马1");
            car1.setJer(1000);
            p3.getCar1().setJer(1);
            p3.getCar1().setName("干你妈");
        }
        System.out.println("P1:" + p1);
        System.out.println("p2:" + p2);
        System.out.println("p3:" + p3);
        System.out.println("================================================================================");

        person1 p12 = new person1(p1);
        person1 p22 = cloneUtil.cloneObject(p12);
        System.out.println("P12:" + p12);
        System.out.println("p22:" + p22);
        System.out.println("================================================================================");

        car.setName("宝马22");
        car.setColor("red");

        System.out.println("P12:" + p12);
        System.out.println("P1:" + p1);
        System.out.println("p22:" + p22);
        System.out.println("================================================================================");

        System.out.println("p22:" + p22);
    }
}
